/*
Copyright 2000-2011 Francois de Bertrand de Beuvron

This file is part of CoursBeuvron.

CoursBeuvron is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

CoursBeuvron is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with CoursBeuvron.  If not, see <http://www.gnu.org/licenses/>.
 */
package fr.insa.beuvron.tps.m2.dessin2DV1;

public class Segment extends Figure {

    private Point p1;
    private Point p2;

    public Segment() {
    }

    public Segment(Point p1, Point p2) {
        this.p1 = p1;
        this.p2 = p2;
    }

    public static Segment cree(Point p1, Point p2) {
        return new Segment(p1, p2);
    }

    public static Segment demande() {
        System.out.println("entrez le point du début du segment : ");
        Point p1 = Point.demande();
        System.out.println("entrez le point de fin du segment : ");
        Point p2 = Point.demande();
        return Segment.cree(p1, p2);
    }

    public Point getP1() {
        return p1;
    }

    public void setP1(Point val) {
        this.p1 = val;
    }

    public Point getP2() {
        return p2;
    }

    public void setP2(Point val) {
        this.p2 = val;
    }

    @Override
    public double maxX() {
        return Math.max(this.p1.maxX(), this.p2.maxX());
    }

    @Override
    public double minX() {
        return Math.min(this.p1.minX(), this.p2.minX());
    }

    @Override
    public double maxY() {
        return Math.max(this.p1.maxY(), this.p2.maxY());
    }

    @Override
    public double minY() {
        return Math.min(this.p1.minY(), this.p2.minY());
    }

    @Override
    public String toString() {
        return "[" + this.p1 + " , " + this.p2 + "]";
    }

}
